Published 2006-11-24 15:02:00

Having just released the increadibly minor update to the Flexy Template Engine in pear, I can now release the documentation that goes with it...

FlexyFramework, with HTML_Template_Flexy include the ability quickly create multilingual websites, by translating the templates.

I've set this up a few times now, and kept meaning to document it. - So here it goes.

Having set up FlexyFramework, (see the previous post about this),

... The full instructions are in the Extended entry....

Step 1) - Update your pearball (as my last version didn't include all the dependancies needed for this.)
wget http://www.akbkhome.com/svn/akpear/make_pearball.sh
#check and edit!
sh make_pearball.sh
cd /var/www/myproject
tar xvfz /var/www/pearball-*****.tgz

Step 2) - Create an alternative bootstrapper. (eg. index.zh_HK.php)

<?php
// set up the include path to work! - our project, and our private pear install
ini_set('include_path',
realpath(dirname(__FILE__)) . ":"
. PATH_SEPARATOR . realpath(dirname(__FILE__)) . '/pear'
);

require_once 'HTML/FlexyFramework.php';



HTML_FlexyFramework::factory(array(
// all of these are available via PEAR::getStaticProperty('__section__','options')
'HTML_FlexyFramework' => array(
'project' => 'MyProject', // our project name
'use_cookies' => 1, // dont use phpsess url for sessoins
'file' => '.disabled', // dont load config from /ConfigData
// - that was an old way of doing things
'auth_class_file' => false, // dont try and load an authentication module.
),

'HTML_Template_Flexy' => array(
'locale' => 'zh_HK.UTF-8', // our locale
'Translation2' => array( // settings for Translation 2 constructor
'driver' => 'gettext', // we are using gettext driver.
'options' => array(
'prefetch' => false,
'langs_avail_file' => 'langs.ini', // these files are in this dir.
'domains_path_file' => 'domains.ini',
'default_domain' => 'myproject',
'file_type' => 'po',
)),
'compileDir' => ini_get('session.save_path') . '/myproject_zh_HK',
),
'Myproject' => array( // our project varoable
// put project options in here..
),

// set up the database connection + path to dataobjects.

'DB_DataObject' => array(
'database' => '.....', // fill in the correct details here!
'schema_location' => 'Myproject/DataObjects',
'class_location' => 'Myproject/DataObjects',
'require_prefix' => 'Myproject/DataObjects/',
'class_prefix' => 'Myproject_DataObjects_',
//'quote_identifiers' = 1
),
));

2) Create a class to wrap the Translator tool: MyProject/Translator.php

<?php

require_once 'HTML/Template/Flexy/Translator.php';

// you could extend the project class, to inherit authentication.
class MyProject_Translate extends HTML_FlexyFramework_Page

{
var $masterTemplate = 'master_translate.html';

function getAuth()
{
return true; // you may want to use the project authentication here
}

function start() // deals with get & post.
{
$flexyOpts = PEAR::getStaticProperty('HTML_Template_Flexy','options');
$t = new HTML_Template_Flexy_Translator(array(
'baseLang' => 'en',
'targetLangs' => array('zh_HK.UTF-8', 'zh_CN.UTF-8', 'ja_JP.UTF-8'),
'appURL' => $this->baseURL.'/Translate.html', // == this class is the action class
'Translation2' => $flexyOpts['Translation2'],
));
if ($e = $t->process($_GET, $_POST)) {
// display errors.. - a bit of a hack..
print_r($e);
}
$this->translator = $t;
}

function outputBody() {
$this->translator->outputDefaultTemplate();
}
}



3) create a wrapper template for the translator.
MyProject/templates/master_translate.html

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Your Project Translator</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
{outputBody():h}
</body>
</html>



4) Create the domains.ini (in the root directory of the project (eg. /var/www/myproject/domains.ini
myproject = ./locale
NOTE: domains.ini needs to be writable on the server you edit the translation files.
5) Create the domains.ini (in the root directory of the project (eg. /var/www/myproject/langs.ini

[en]
name = English
encoding = iso-8859-1

[zh_HK.UTF-8]
name = Traditional Chinese
encoding = utf-8

;[zh_CN.UTF-8]
;name = Simplified Chinese
;encoding = utf-8

;[ja_JP.UTF-8]
;name = Japanese
;encoding = utf-8

now see if visiting http://yourwebsite/myproject/index.php/Translate.html works....



Mentioned By:
google.com : php multilanguage (112 referals)
google.com : FlexyFramework (70 referals)
google.com : november (63 referals)
google.com : php multi language (56 referals)
www.planet-php.net : Planet PHP (51 referals)
google.com : april (51 referals)
google.com : flexy svn (37 referals)
google.com : php multi-language (27 referals)
google.com : flexy translation2 (23 referals)
google.com : db_dataobject utf8 (20 referals)
google.com : multilanguage php (19 referals)
google.com : db_dataobject utf-8 (13 referals)
google.com : php multilanguage class (13 referals)
google.com : flexy setup (12 referals)
google.com : flexy multilanguage (10 referals)
google.com : pear flexy (10 referals)
google.com : php Multilanguage template (9 referals)
google.com : php multilanguage array (8 referals)
google.com : flexy (7 referals)
google.com : flexy translate (6 referals)

Add Your Comment